package com.da.javatest.leetCode;

/**
 * @author chenlida
 * @date 2019/1/16 16:23
 * @description
 */
public class Code495 {
    public int findPoisonedDuration(int[] timeSeries, int duration) {
        if (timeSeries.length == 1) {
            return duration;
        }
        int total = 0;
        for (int i = 1; i < timeSeries.length; i++) {
            if (i == 1) { total += duration; }
            if (timeSeries[i] - timeSeries[i - 1] < duration) {
                total += timeSeries[i] - timeSeries[i - 1];
            } else {
                total += duration;
            }
        }
        return total;
    }
}
